﻿using Mengsk.ProxyDelivery.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Mengsk.ProxyDelivery.Note
{
    /// <summary>
    /// CreateNoteWindow.xaml 的交互逻辑
    /// </summary>
    public partial class CreateNoteWindow : Window
    {

        private NoteService noteService = ServiceContainer.GetService<NoteService>();

        public CreateNoteWindow()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                long orderId = 0;
                string goodsInfo = this.tbGoodsInfo.Text.Trim();
                string comment = this.tbComment.Text.Trim();
                long.TryParse(this.tbOrderId.Text.Trim(), out orderId);

                if (string.IsNullOrWhiteSpace(comment))
                {
                    throw new Exception("描述信息不能为空");
                }
                noteService.Create(orderId, goodsInfo, comment, 0, this.chkType.IsChecked.Value ? 1 : 2, DateTime.MinValue);
                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
